//
//  ApplyAcGoalCell.m
//  KuWoCan
//
//  Created by hwd on 17/3/16.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "ApplyAcGoalCell.h"

@implementation ApplyAcGoalCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI
{
    UILabel *leftLab = [UILabel new];
    leftLab.font = KwFont(15);
    leftLab.textColor = KwBlueColor;
    leftLab.text = @"活动目的";
    [self addSubview:leftLab];
    [leftLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.top.equalTo(@20);
        make.height.equalTo(@15);
    }];
    
    //促销目的（1推动渠道2提升认知3推动试用4提高使用量5推动忠诚度）
    
    NSArray *btnTitleArr = @[@"推动渠道",@"提升认知",@"推动试用",@"提高使用量",@"推动忠诚度"];
    
    
    float x= ([UIScreen mainScreen].bounds.size.width - 25*2 - 100*3)/2;
    
    for (int i = 0; i < btnTitleArr.count; i++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 100+i;
        btn.titleLabel.font = KwFont(14);
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitle:btnTitleArr[i] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"yuan"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"yuan_sel"] forState:UIControlStateSelected];
        [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
        [btn addTarget:self action:@selector(selectBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
    }
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = KwGaryColor;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@1.5);
        make.left.equalTo(@25);
        make.right.equalTo(@-25);
        make.top.equalTo(leftLab.mas_bottom).offset(70);
    }];
    
    
    for (int i = 0; i < btnTitleArr.count; i++)
    {
        
        UIButton *currtenBtn = (UIButton *)[self viewWithTag:100+i];
        UIButton *nextBtn = [self viewWithTag:100+i+1];
        UIButton *lastBtn = [self viewWithTag:100+i-1];
        
        [currtenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            if (i == 0 || i == 3)
            {
                make.left.equalTo(@25);
                make.right.equalTo(nextBtn.mas_left).offset(-x);
            }
            else if (i == 2)
            {
                make.right.equalTo(@-25);
                make.left.equalTo(lastBtn.mas_right).offset(x);
            }
            else if (i == 4)
            {
                make.left.equalTo(lastBtn.mas_right).offset(x);
            }
            else
            {
                make.right.equalTo(nextBtn.mas_left).offset(-x);
                make.left.equalTo(lastBtn.mas_right).offset(x);
            }
            
            if (i < 3)
            {
                make.top.equalTo(leftLab.mas_bottom).offset(30);
            }
            else
            {
                make.top.equalTo(lineView.mas_bottom).offset(20);
                make.bottom.equalTo(@-20);
            }
            
            make.width.equalTo(@100);
            make.height.equalTo(@30);
        }];
    }
}

- (void)selectBtn:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (_block)
    {
        _block(btn.tag);
    }
}


@end
